package com.ruben.study;

import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
import com.baomidou.mybatisplus.core.toolkit.support.LambdaMeta;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;

import java.util.List;

/**
 * 序列化Lambda例子
 *
 * @author <achao1441470436@gmail.com>
 * @since 2021/9/28 12:43
 */
public class SerializeLambdaDemo {
    public static void main(String[] args) {
        List<String> list = List.of("123", "456");
        String sqlification = Sql.<Demo>sqlification(demo -> demo.getName().startsWith("123") || demo.getName().endsWith("456") && demo.enabled && list.contains(demo.name));
        System.out.println(sqlification);
    }

    static class Sql {
        public static <T> String sqlification(SFunction<T, ?> func) {
            final LambdaMeta lambda = LambdaUtils.extract(func);
            final Class<?> instantiatedClass = lambda.getInstantiatedClass();
            System.out.println(lambda.getImplMethodName());
            System.out.println(instantiatedClass);
            return "";
        }
    }

    class Demo {
        public Boolean enabled;
        Long id;
        String name;

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }


}
